package cn.tpshion.devops.controller;

import cn.tpshion.devops.common.Result;
import cn.tpshion.devops.domain.dto.SecretDTO;
import cn.tpshion.devops.domain.entity.SecretData;
import cn.tpshion.devops.service.SecretService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/secret")
public class SecretController {

    @Resource
    private SecretService secretService;

    @PostMapping("/secretList")
    public Result<List<SecretData>> secretList(){
        return Result.ok(secretService.secretList());
    }

    @PostMapping("/addSecret")
    public Result addSecret(@Valid @RequestBody SecretData data){
        secretService.addSecret(data);
        return Result.ok();
    }

    @PostMapping("/deleteSecret")
    public Result deleteSecret(@Valid @RequestBody SecretDTO dto){
        secretService.deleteSecret(dto);
        return Result.ok();
    }
}
